package nz.ac.massey.doi_information_extractor.tests;

import static org.junit.Assert.*;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import nz.ac.massey.doi_information_extractor.data.Publication;
import nz.ac.massey.doi_information_extractor.parser.ScienceDirectPlugin;

import org.junit.Before;
import org.junit.Test;

// This class contains rudimentary tests for the ScienceDirectPlugin class. It's based on http://dx.doi.org/10.1016/j.jct.2010.07.014, one of Jen's papers.

public class ScienceDirectPluginTest2 {

	Publication newpub;

	@Before
	public void setUp() throws Exception{
		System.setProperty("http.proxyHost", "tur-cache.massey.ac.nz");
		System.setProperty("http.proxyPort", "8080");

		//This is the reason the tests take so long.
		ExecutorService pool = Executors.newFixedThreadPool(1);
		Callable<Publication> scienceDirectPlugin = new ScienceDirectPlugin("10.1016/j.jct.2010.07.014");
		Future<Publication> futureBibsonomyPluginResult = pool.submit(scienceDirectPlugin);

		newpub = futureBibsonomyPluginResult.get();
	}

	@Test
	public void tests() throws Exception{
		assertTrue(newpub.getKeywords().equals("Alkanol; Ionic liquid; Thermophysical properties; (Vapour&nbsp;+&nbsp;liquid) equilibrium"));

		assertTrue(newpub.getUrl().startsWith("http://www.sciencedirect.com/science?_ob=MImg"));

		assertTrue(newpub.getDescription().equals("Densities and speeds of sound have been determined for the binary mixture (1-butylpyridinium tetrafluoroborate&nbsp;+&nbsp;methanol, or ethanol) over the temperature range 293.15&nbsp;K to 323.15&nbsp;K. From experimental values, excess volume and excess isentropic compressibility have been calculated. The mixtures give negative values for the excess properties. Besides, (vapour&nbsp;+&nbsp;liquid) equilibrium in isothermal conditions has been obtained for these systems at <i>T</i>&nbsp;=&nbsp;303.15&nbsp;K and <i>T</i>&nbsp;=&nbsp;323.15&nbsp;K, which has allowed us to derive activity coefficients and excess Gibbs functions. Positive deviations from Raoult&#x2019;s law have been found. A detailed analysis and interpretation of results have been carried out in structural and energetic terms using thermodynamic information of the pure compounds.  ") && (newpub.getDescription().length() <= 1012));

		assertTrue(newpub.getDoi().equals("http://dx.doi.org/10.1016/j.jct.2010.07.014"));

		assertTrue(newpub.getVolumeNumber().equals("42"));
		
		assertTrue(newpub.getEdition().equals("12"));

		assertTrue(newpub.getArticleTitle().equals("Thermodynamic study of binary mixtures containing 1-butylpyridinium tetrafluoroborate and methanol, or ethanol"));

		assertFalse(newpub.equals(null));

		assertTrue(newpub.getAuthors().size() == 5);

		assertTrue(newpub.getAuthors().get(0).getOrganisation().equals("Departamento de Qu&#xed;mica Org&#xe1;nica-Qu&#xed;mica F&#xed;sica, Facultad de Ciencias, Universidad de Zaragoza, 50009 Zaragoza, Spain"));

		assertTrue(newpub.getPublicationTitle().equals("The Journal of Chemical Thermodynamics"));

		assertTrue(newpub.getPageNumbers().equals("1500-1505"));

		assertTrue(newpub.getDate().equals("December 2010"));
	}
}